home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / dxcmds34.sit / Dartmouth XCMD's 3.4.3 / card_6552.txt < prev    next >
Text File  |  1990-04-17  |  3KB  |  141 lines

  1. -- card: 6552 from stack: in.3
  2. -- bmap block id: 0
  3. -- flags: 4000
  4. -- background id: 3241
  5. -- name: LeafName
  6. ----- HyperTalk script -----
  7. on Install
  8.   get ChooseTargetStack()
  9.   InstallResource XFCN,LeafName,it
  10. end Install
  11.  
  12.  
  13. -- part 1 (field)
  14. -- low flags: 81
  15. -- high flags: 0007
  16. -- rect: left=12 top=26 right=298 bottom=491
  17. -- title width / last selected line: 0
  18. -- icon id / first selected line: 0 / 0
  19. -- text alignment: 0
  20. -- font id: 22
  21. -- text size: 10
  22. -- style flags: 0
  23. -- line height: 13
  24. -- part name: Source
  25.  
  26.  
  27. -- part 3 (button)
  28. -- low flags: 00
  29. -- high flags: A003
  30. -- rect: left=299 top=300 right=322 bottom=438
  31. -- title width / last selected line: 0
  32. -- icon id / first selected line: 0 / 0
  33. -- text alignment: 1
  34. -- font id: 0
  35. -- text size: 12
  36. -- style flags: 0
  37. -- line height: 16
  38. -- part name: Show Pascal Source
  39. ----- HyperTalk script -----
  40. on mouseUp
  41.   set the visible of card field 1 to not the visible of card field 1
  42.   if the visible of card field 1 is true then
  43.     set the name of me to "Hide Pascal Source"
  44.   else set the name of me to "Show Pascal Source"
  45. end mouseUp
  46.  
  47.  
  48.  
  49. -- part contents for background part 16
  50. ----- text -----
  51. LEAFNAME XFCN version 1.5
  52. Kevin Calhoun
  53.  
  54. LeafName takes a full pathname and returns the last component of it.  The last component is the string of characters following the last colon in the pathname.  This is known as the 
  55. "leaf name" of a file or directory.
  56.  
  57. Examples:
  58.  
  59. put LeafName("HD:My Best Years:1962:The Drive-In")  
  60.    --puts The Drive-In into the message box.
  61.  
  62. put LeafName("Winkin:Blinkin:Nod") into theContainer
  63.    --puts Nod into theContainer
  64.  
  65. This XFCN used to be known as LastPathComponent, but that name is too long to type.
  66.  
  67. -- part contents for card part 1
  68. ----- text -----
  69. UNIT LastPathComponent;
  70.  
  71. { LeafName XFCN ┬⌐ 1988-1989 by the Trustees of Dartmouth College }
  72. { Written by Kevin Calhoun }
  73.  
  74. { This source compatible with MPW Pascal 3.0 }
  75.  
  76. (*
  77. Pascal LeafName.p
  78. Link -m ENTRYPOINT Γêé
  79.      -o "YourFile" Γêé
  80.      -rt XFCN=3530 Γêé
  81.      -sn Main=LeafName Γêé
  82.      LeafName.p.o Γêé
  83.     "{PLibraries}"Paslib.o Γêé
  84.     "{Libraries}"HyperXLib.o
  85. *)
  86.  
  87. {$R-}
  88.  
  89. INTERFACE
  90.   USES
  91.     Types,
  92.     HyperXCmd;
  93.  
  94.   PROCEDURE EntryPoint (paramPtr : XCMDPtr);
  95.  
  96. IMPLEMENTATION
  97.  
  98.   PROCEDURE GetLPC(paramPtr : XCMDPtr); FORWARD;
  99.  
  100.   PROCEDURE EntryPoint (paramPtr : XCMDPtr);
  101.   BEGIN
  102.     GetLPC(paramPtr);
  103.   END;
  104.  
  105.   PROCEDURE GetLPC (paramPtr : XCMDPtr);
  106.     VAR
  107.       fullPathName : Str255;
  108.       fileName : Str255;
  109.  
  110.     FUNCTION AfterLastColon (str : Str255) : Str255;
  111.       VAR
  112.         theLength, index : INTEGER;
  113.     BEGIN
  114.       theLength := LENGTH(str);
  115.       index := theLength;
  116.       IF POS(':', str) > 0 THEN
  117.         BEGIN
  118.           WHILE (str[index] <> ':') DO
  119.             BEGIN
  120.               index := index - 1;
  121.             END;
  122.           AfterLastColon := COPY(str, index + 1, theLength - index);
  123.         END
  124.       ELSE
  125.         AfterLastColon := str;
  126.     END;
  127.  
  128.   BEGIN
  129.     IF paramPtr^.paramCount > 0 THEN
  130.       BEGIN
  131.         ZeroToPas(paramPtr, paramPtr^.params[1]^, fullPathName);
  132.         fileName := AfterLastColon(fullPathName);
  133.         paramPtr^.returnValue := PasToZero(paramPtr, fileName);
  134.       END
  135.     ELSE
  136.       paramPtr^.returnValue :=
  137.         PasToZero(paramPtr, 
  138.         'LeafName XFCN 1.5, 15 March 1989, ┬⌐1988-1989 Dartmouth College');
  139.   END;
  140.  
  141. END.